# syntax=docker/dockerfile:1
# Stage 1: 构建
FROM gradle:8.13-jdk21-alpine AS builder
WORKDIR /app

# 复制Gradle配置文件
COPY build.gradle settings.gradle ./
COPY gradle/ ./gradle/
COPY gradlew ./

# 使用缓存挂载下载依赖
RUN --mount=type=cache,target=/home/gradle/.gradle \
    gradle build -x test --no-daemon --dry-run || true

# 复制源代码并构建
COPY src/ ./src/
RUN --mount=type=cache,target=/home/gradle/.gradle \
    gradle --no-daemon build -x test

# Stage 2: 运行环境
FROM eclipse-temurin:21-jdk-alpine
WORKDIR /app
COPY --from=builder /app/build/libs/*.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]
